package com.hjm.app.fragment.user;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.hjm.app.R;
public class FragmentUserRegister extends Fragment implements View.OnClickListener {
    private OnClickListener mListener;
    private EditText etUsername, etPassword;
    private Button btnRegister, btnBack;
    public FragmentUserRegister(OnClickListener listener) {
        // Required empty public constructor
        this.mListener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_user_register, container, false);

        etUsername = view.findViewById(R.id.edit_text_user_register_phone);
        etPassword = view.findViewById(R.id.edit_text_user_register_password);

        btnRegister = view.findViewById(R.id.button_user_register_register);
        btnBack = view.findViewById(R.id.button_user_register_login);


        btnRegister.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.button_user_register_register) {
            mListener.onRegisterClicked(etUsername.getText().toString(), etPassword.getText().toString());
        } else if (v.getId() == R.id.button_user_register_login) {
            mListener.onCancelClicked();
        }
    }

    public interface OnClickListener {
        void onRegisterClicked(String username, String password);
        void onCancelClicked();
    }
}